<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" dir="ltr">
<head>
#headTag('发表新贴')
<script type="text/javascript">
jQuery.fn.outerHTML = function(s) {
	return (s)
	? this.before(s).remove()
	: jQuery("<p>").append(this.eq(0).clone()).html();
};
function addOption() {
	var html = '<p>' + $('#hidden_option').html() + '</p>' + $('#new_flag').outerHTML();
	$("#new_flag").outerHTML(html);
}
$(document).ready(function(){
	addOption();
	addOption();
	addOption();
	addOption();
	$('input[name=multiple]').change(function(){
		var checked = $('input[name=multiple]').attr('checked');
		if(checked){
			$('span.maxChoices').show();
		} else{
			$('span.maxChoices').hide();
		}
	});
	$('input[name=title]').focus();

	$("form").submit(function(){
		var title = $('input[name=title]').val();
		if($.trim(title).length == 0){
			alert("标题必须填写");
			return false;
		}

		var options = new Array();
		if($('input[name=options]').val() != undefined){
			$('input[name=options]').each(function(){
				var option = $(this).val();
				if($.trim(option).length != 0){
					options.push($.trim(option));
				}
			});
			if(options.length < 2){
				alert("至少需要填写 2 个选项");
				return false;
			}
		}

		var content = KE.util.getData("topic_content");
		if($.trim(content).length < 10){
			alert("内容太短了，不能发表");
			return false;
		}
	
		var categoryId = $('select.select-category:last').val();
		if(categoryId == 0){
			alert("请选择栏目");
			$("input[type='submit']").removeAttr("disabled");
			return false;
		}
		var days = $('input[name=expiration]').val();
		var publicVoters = $('input[name=publicVoters]').val();
		var data = {title:title, content:content, categoryId:categoryId, vote:{options:options, days:days, publicVoters:publicVoters}};
		$.postJSON($(this).attr('action'), data, function(json){
			if(json.success){
				location.href=json.returnObject;
			} else {
				$("input[type='submit']").after('<span class="error" style="color:red;">*' + json.message + '</span>');
				$("input[type='submit']").removeAttr("disabled");
			}
		});
		
		return false;
	});
});
</script>
</head>
<body>
<div id="page">
#parse("default/_header.htm")
<div id="middle">
<div id="main_wrap">
	<div id="main">
		#topbar()
		<div class="center">
			<div id="new_topic">
				<form action="${url.base}/topic" method="post" accept-charset="UTF-8" enctype="application/x-www-form-urlencoded; charset=UTF-8">
				<div class="wrap">
					<h3>发表投票</h3>
					<input type="text" size="70" style="height:17px;" name="title" autocomplete="off"/> *标题*
					#if($category.children.size()>0)
						<select autocomplete="off" class="select-category">
							<option value="0">...</option>
							#foreach($cat in $category.children)
							<option value="$cat.id">$cat.name</option>
							#end
						</select>
					#end
					<div class="vote">
					<input type="hidden" value="vote" name="type"/>
					<p>选项:每行填写 1 个选项 最多可填写 50 个选项</p>
					<div class="option">
						<span id="new_flag"></span>
						<p style="display:none;" id="hidden_option">
							<input name="options" type="text" autocomplete="off"/>
							<a onclick="this.parentNode.parentNode.removeChild(this.parentNode)" class="close" title="删除" href="javascript:;">×</a>
						</p>
						<p>
							<a onclick="addOption()" href="javascript:;">+增加一项</a>
						</p>
					</div>
					
					
					<div class="config">
						<p>
							<input type="checkbox" value="true" name="multiple"/>多选投票<span class="maxChoices" style="display:none;">，最多选<input value="2" type="text" size=1 maxlength="1" name="maxChoices">项</span>
						</p>
						<p>
							<input type="checkbox" checked="checked" value="1"/>记票天数:
							<input type="text" size=2 value="30" name="expiration"/>
						</p>
						<p>
							<input type="checkbox" value="true" name="publicVoters"/>公开投票参与人
						</p>
					</div>
					<div class="clear"></div>
					</div>
					<script type="text/javascript">
					KE.show({
						id : 'topic_content',
						items: ['fullscreen', 'undo', 'redo', 'justifyleft', 'justifycenter', 'justifyright',
					'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'hr', 'table', 'link', 'unlink', '-',
					'fontname', 'fontsize', 'textcolor', 'bgcolor', 'bold',
					'italic', 'underline', 'strikethrough', 'removeformat', 'media',
					'flash', 'image', 'emoticons']
					});
					</script>
					<div class="editor">
						<textarea id="topic_content" style="width:100%;height:380px;" name="content"></textarea>
					</div>
					<input type="submit" class="submit" value="发布投票"/>
				</div>
				</form>
			</div>
		</div>
	</div>
</div>
#parse("default/_sidebar.htm")
</div>
<div class="clear"></div>
</div>
#parse("default/_footer.htm")
</body>
</html>